import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    id: 0,
    username: 'nowcoder',
    headerUrl: 'http://images.nowcoder.com/head/1t.png',
    type: 0
  }),
  actions: {
    updateUsername(username) {
      if (username) {
        this.username = username
      } else {
        this.username = 'http://images.nowcoder.com/head/1t.png'
      }
    },
    updateHeaderUrl(url) {
      if (url) {
        this.headerUrl = url
      } else {
        this.headerUrl = 'http://images.nowcoder.com/head/1t.png'
      }
    },
    resetDefault() {
      this.id = 0
      this.username = 'nowcoder'
      this.headerUrl = 'http://images.nowcoder.com/head/1t.png'
      this.type = 0
    }
  },
  // 开启数据持久化
  persist: {
    enabled: true
  }
})
